package com.example.superoa.model.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.dao.RapplyDao;
import com.example.superoa.model.mappers.RcountMapper;
import com.example.superoa.model.pojos.Rapply;
import com.example.superoa.model.pojos.Rplan;
import com.example.superoa.model.pojos.Staff;

@Service
@Transactional(rollbackFor=Exception.class)
public class RcountService {
		@Autowired
		private RcountMapper countmapper;
		@Autowired
		private RapplyDao appdao;
				
		//查询所有
		public JSONArray findAllscount() {
			return countmapper.findAllscount();
		}
		/**新增
		 * @param apply
		 */
		public void insertrapply(Rapply apply,Integer Staff_id,Integer staff_id,Integer rplanid) {
			Staff staff1=new Staff();
			Staff staff2=new Staff();
			Rplan rplan=new Rplan();
			staff1.setStaffId(staff_id);
			staff2.setStaffId(Staff_id);
			rplan.setRplanid(rplanid);
			apply.setRplan(rplan);
			apply.setStaff1(staff1);
			apply.setStaff2(staff2);
			apply.setRapplyreason("招聘申请");
			apply.setRapplyspstatue(0);
			apply.setRapplytime(new Date());
			appdao.save(apply);
		}	
		/**根据创建人 模糊查询简历
		 * @param name
		 * @return
		 */
		public JSONArray findByNamecount(String Staff_name){
			return countmapper.findByNamecount("%"+Staff_name+"%");
		}
		//根据id查询
		public JSONArray findByIdapply(int rapplyid) {
			return countmapper.findByIdapply(rapplyid);
		}
		/**编辑
		 * @param id
		 * @return
		 */
		public void xiugaiapply(int rapplyid, int rapplynums, Date rapplystart, Date rapplyend) {
			Rapply rapply = appdao.findById(rapplyid).get();
			rapply.setRapplyend(rapplyend);;
			rapply.setRapplynums(rapplynums);;
			rapply.setRapplystart(rapplystart);
			appdao.save(rapply);
		}
}